<template>
  <div style="padding: 10px">

    <view>库存管理方法：再订货点库存法</view>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="index" width="50"  label="序号"/>
      <el-table-column prop="carPartsName" label="汽车配件名称" width="120"/>
      <el-table-column prop="standard" label="规格" width="50"/>
      <el-table-column prop="carNumber" label="配件编号" width="100"/>
      <el-table-column prop="number" label="剩余数量" width="100"/>
      <el-table-column prop="sub_number" label="缺货数量" width="100"/>
      <el-table-column prop="safe_number" label="安全库存" width="100"/>

      <el-table-column prop="adv_number" label="建议最少订货量" width="100"/>
      <el-table-column fixed="right" label="操作" width="120">
        <template #default="scope">
          <el-button type="text" @click="dinghuo(scope.row)">订货</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog v-model="dialogVisible" title="进货单" style="display: flex" width="30%">
      <el-form :model="form" label-width="120px">
        <div style="display: flex">
          <el-form-item label="购买方">
            <el-input v-model="form.buy_company" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="销售方">
            <el-input v-model="form.company" style="width: 80%" ></el-input>
          </el-form-item>
        </div>
        <div style="display: flex">
          <el-form-item label="汽车配件名称">
            <el-input v-model="form.userName" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="规格">
            <el-input v-model="form.email" style="width: 80%" ></el-input>
          </el-form-item>
        </div>
        <div style="display: flex">
          <el-form-item label="配件编号">
            <el-input v-model="form.userName" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="单价">
            <el-input v-model="form.email" style="width: 80%" ></el-input>
          </el-form-item>
        </div>
        <div style="display: flex">
          <el-form-item label="订购量">
            <el-input v-model="form.userName" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="总计">
            <el-input v-model="form.email" style="width: 80%" ></el-input>
          </el-form-item>
        </div>
      </el-form>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="save">确定</el-button>
      </span>
      </template>
    </el-dialog>

  </div>
</template>
<script>
import request from "@/utils/request";
import {View} from "@element-plus/icons-vue";

export default {
  name: "PurchasingManagement",
  data() {
    return {
      form: {
        carPartsName:null,
        standard:null,
        carNumber:null,
        buy_price:null,
        sale_price:null,
        number:null,
        sub_number:null,
        cover:null
      },
      dialogVisible:false,
      currentPage: 1,
      total: 10,
      tableData: []
    }
  },
  created() {
    this.load()
  },
  methods: {
    dinghuo(row){
      this.dialogVisible=true
    },
    load() {
      request.get("/goods").then(res => {
        console.log(res)
        this.tableData = res.data
        for(let i=0;i<this.tableData.length;i++){
          if(this.tableData[i].number!==0&&this.tableData[i].number<this.tableData[i].safe_number){
            this.tableData[i].adv_number=this.tableData[i].safe_number-this.tableData[i].number;
          }else if(this.tableData[i].number===0){
            this.tableData[i].adv_number=this.tableData[i].safe_number+this.tableData[i].sub_number
          }else {
            this.tableData[i].adv_number=0
          }
        }
      })
    },


  }
}
</script>

<style scoped>

</style>
